
/**
 ******************************************************************************
 * @file           : lmx2572.h
 * @brief          : PLL
 ******************************************************************************
 * @attention
 *  Copyright (c) 2021  awptech.co.ltd.
 * All rights reserved.
 ******************************************************************************
 */

#pragma once

#ifdef __cplusplus
extern "C"
{
#endif

#include "stm32h7xx_hal.h"
#include "spi.h"
#include "gpio.h"

  typedef struct
  {
    SPI_HandleTypeDef *spi_dev;
    GPIO_TypeDef *gpio;
    uint16_t pin;
  } lmx2572_dev_t;

  typedef struct
  {
    uint8_t reg;
    uint16_t value;
  } lmx2575_reg_value_table_t;

  typedef void *lmx2572_handle_t; /*!< handle of lmx2572 */

  typedef enum
  {
    LMX2572_SLEEP_ALL_ON = 1,
    LMX2572_SLEEP_ALL_OFF,
    LMX2572_SLEEP_ALL_2,
    LMX2572_SLEEP_ALL_3,
  } lmx2572_sleep_sub_e;

  extern const uint16_t vcox[6][6];
  lmx2572_handle_t lmx2572_create(SPI_HandleTypeDef *hspi, GPIO_TypeDef *g, uint16_t p);
  uint8_t lmx2572_delete(lmx2572_handle_t *p_dev);
  uint8_t lmx2572_reg_init(lmx2572_handle_t dev, const lmx2575_reg_value_table_t table[]);
  uint8_t lmx2572_write_reg(lmx2572_handle_t dev, uint8_t reg, uint16_t reg_value);
  uint8_t lmx2572_read_reg(lmx2572_handle_t dev, uint8_t reg, uint16_t *reg_value);
  void lmx2572_sleep(lmx2572_handle_t dev, uint8_t ONorOFF);
  void lmx2572_sleep_44(lmx2572_handle_t dev, uint8_t ONorOFF, lmx2572_sleep_sub_e type);
  uint8_t lmx2572_check_self(lmx2572_handle_t dev);

#ifdef __cplusplus
}
#endif
